package com.cx.base.day12_framework.collection;

import com.cx.base.day19_thread.Test;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

/**
 * @Author: robert.song
 * @Date: Created in 2021/8/11
 */
@Slf4j(topic = "Collection_")
public class Collection_ {
    public static void main(String[] args) {
        List<String> list = new ArrayList();
//        add
//        不去重
        list.add("jack");
        list.add("jack");
        list.add("jack");
//        list.add(10);
//        list.add(10);
//        list.add(10);
//        list.add(true);
//        list.add(true);
//        list.add(true);
//        remove
//        按索引删除
        list.remove(0);
//        按照value删除
        log.debug("debug");
        list.remove("jack");
        log.info("list:{}", list);
        list.set(0, "haha");

        int i = 0;
        for (Object l : list) {
            log.debug(i++ + "debug: {}", l);
        }
//        contains
        log.info("list contain jack? {}", list.contains("jack"));
//        size
        log.info("list size: {}", list.size());
//        isEmpty
        log.info("list isEmpty? {}", list.isEmpty());
//        clear
        list.clear();
        log.info("list isEmpty after execute list.clear()? {}", list.isEmpty());
//        addAll
        List list2 = new ArrayList();
        list2.add("红龙");
        list2.add("钢铁之心");
        list2.add("红色警戒3");
        list.addAll(list2);
        List list3 = new ArrayList();
        list3.add(new Book());
        list.addAll(list3);
        log.info("list after execute method addAll(list2): {}", list);
//        containsAll
        log.info("list contrains list2? {}", list.containsAll(list2));
//        removeAll
        log.info("list execute method removeAll()");
        list.removeAll(list2);
        list.add("jack");
        list.add("jack");
        list.add("jack");
//        list.add(10);
//        list.add(10);
//        list.add(10);
//        list.add(true);
//        list.add(true);
//        list.add(true);
        log.info("list: {}", list);

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
//      只能打印字符型
//        list.forEach(System.out::println);
//        看着是foreach，底层仍然是迭代器，可反编译查看
        for (Object l : list) {
            System.out.println(l);
        }

//        HashMap hm = new HashMap();


        String s1 = "sss";
        System.out.println(s1);
        String s2 = new String("liang");
        s2.intern();
        System.out.println(s2);
        String s3 = s2;
        System.out.println(s3);

        test();
    }

    public static void test() {
        Test t = new Test();
        String a = new String("liang");
        System.out.println(a);
    }
}

